util = {
	/*com.tjwx.util.js公共组件和工具方法*/
	
	/*正则表达式校验*/
	mRegExp: {
		email: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
		pwd: /^[a-zA-Z0-9][a-zA-Z0-9]{4,14}[a-zA-Z0-9]$/,
		// 备用 pwd:     /(?!^\d+$)(?!^[cytoscape-zA-Z]+$)[0-9a-zA-Z]{5,14}/,
		phone:/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/  ,	//  /^\d{11}$/
		checkIdCard: /^\d{17}[xX0-9]$/,
		chineseChar: /^[\u4e00-\u9fa5]+$/,
		chChar: /[^\x00-\xff]+/,
		neChar: /^[0-9a-zA-Z]*$/g,
		enterpriseName: /^[\u4e00-\u9fa5\(\)\（\）]+$/,
		enterpriseCode: /^[\d\-]+$/,
		tel: /^(\d{11})$|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/,
		httpsrc: /^(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:/~+#-]*[\w@?^=%&amp;/~+#-])?$/,
		floatNum:/^[0-9]+(\.[0-9]{2})?$/,  //包括0的数字和两位小数		//	不包括0的数字和小数  /^([1-9]+(\.[0-9]{2})?|0\.[1-9][0-9]|0\.0[1-9])$/ 不允许0的话//正则表达式 验证数字格式  非负数 小数点后保留两位   /^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/
		intNum:/^\+?(0|[1-9][0-9]*)$/, //正则表达式 验证数字格式 正整数包括0 不包括0的可以这样写 /^[0-9]*[1-9][0-9]*$/
		special:/^[^\~!@#$%^&*《》<>:{}]*$/,
	},
	
	//分页组件
	pages: {	
        isIndexPage: false,
        generatePageNav: function (data, start, method, pagectn) {
            var pages = Math.ceil(data / 20); //获取总页数
            var pageDom = (pagectn == undefined) ? $(".page-nav") : $(pagectn);
            pageDom.empty();
            var temp = $("<div></div>"), _li;

            if (pages != 0) {
                _li = $("<li method='" + method + "' class='active first-page-btn'>首页</li>");
                temp.append(_li);
            }

            if (start != 1) {
                _li = $("<li method='" + method + "' class='active prev-btn'>上一页</li>");
                temp.append(_li);
            }

            start = parseInt(start);
            if (pages > 5) {
                if (pages - start > 2) {
                    if (start > 3) {
                        var stag = start - 2;
                        var ltag = start + 2;
                        for (var i = stag; i <= ltag; i++) {
                            if (i == start) {
                                _li = $("<li method='" + method + "' class='normal-btn cur'>" + i + "</li>");
                            } else {
                                _li = $("<li method='" + method + "' class='normal-btn'>" + i + "</li>");
                            }
                            temp.append(_li);
                        }
                    } else { //直接输出前五个
                        for (var i = 1; i <= 5; i++) {
                            if (i == start) {
                                _li = $("<li method='" + method + "' class='normal-btn cur'>" + i + "</li>");
                            } else {
                                _li = $("<li method='" + method + "' class='normal-btn'>" + i + "</li>");
                            }
                            temp.append(_li);
                        }
                    }
                } else {
                    for (var i = pages - 4; i <= pages; i++) {
                        if (i == start) {
                            _li = $("<li method='" + method + "' class='normal-btn cur'>" + i + "</li>");
                        } else {
                            _li = $("<li method='" + method + "' class='normal-btn'>" + i + "</li>");
                        }
                        temp.append(_li);
                    }
                }
            } else {
                for (var i = 1; i <= pages; i++) {
                    if (i == start) {
                        _li = $("<li method='" + method + "' class='normal-btn cur'>" + i + "</li>");
                    } else {
                        _li = $("<li method='" + method + "' class='normal-btn'>" + i + "</li>");
                    }
                    temp.append(_li);
                }
            }

            if (pages > 1 && start != pages) {
                _li = $("<li method='" + method + "' class='active next-btn'>下一页</li>");
                temp.append(_li);
            }

            if (pages == 0) {
                pages = 1;
            } else {
                _li = $("<li method='" + method + "' class='active last-page-btn'>末页</li>");
                temp.append(_li);
            }

            pageDom.html(temp.html()).attr("total", pages);
			$("#total").html(data);
        }
    },
	
	
	/*通用信息提示*/
	tips: {
        timer: null,

        basicTimer: null,

        basic: function (text) {
            if ($(".basic-toast").length > 0) {
                $(".basic-toast").text(text).show();
            } else {
                var toast = $('<div class="basic-toast">' + text + '</div>');
                $("body").append(toast);
            }

            clearTimeout(util.tips.basicTimer);
            util.tips.basicTimer = setTimeout(function () {
                $(".basic-toast").fadeOut();
            }, 3000);
        },

        show: function (text, isGifShow) {
            if ($(".toast-ctn").length == 0) {
                var tipsDom = $("<div class='toast-ctn'><span class='toast'>" + text + "</span></div>");
                if (isGifShow) {
                    var lGif = $("<i class='loadingGif'></i>");
                    $(".toast", tipsDom).addClass("toast-gif").append(lGif);
                } else {
                    $(".toast", tipsDom).removeClass("toast-gif");
                    $(".loadingGif", tipsDom).remove();
                }
                $("body").append(tipsDom);
            } else {
                if (isGifShow) {
                    $(".toast-ctn").append($("<span class='toast toast-gif'><i class='loadingGif'></i>" + text + "</span>"));
                } else {
                    $(".toast-ctn").append($("<span class='toast'>" + text + "</span>"));
                }
                $(".toast-ctn").show();
            }
            if ($(".toast").length > 1) {
                $(".toast").eq(0).fadeOut().remove();
            }
        },

        hide: function () {
            $(".toast-ctn").fadeOut();
        }
    },
	
	/*时间组件*/
    data: {
		//2017-01-01 10:22:22 -> 2017-01-01
		stringToDate:function(strDate){
			strDate = strDate.replace(/(\d{4}).(\d{1,2}).(\d{1,2}).+/mg, '$1-$2-$3'); 
			return strDate; 
		},
		
		formatData:function(time){
			var _timestring = time;
			var newDate = new Date();
			newDate.setTime(_timestring * 1000);

			var formatTime = newDate.getFullYear() + "-" + ( ( (newDate.getMonth() + 1) >= 10) ? newDate.getMonth() + 1 : "0" + (newDate.getMonth() + 1)) + "-" + ( ( newDate.getDate()  >= 10) ? newDate.getDate() : ("0" + newDate.getDate()) ) + " " + (  ( newDate.getHours() >=10  )? newDate.getHours() : ( "0" +  newDate.getHours() )  ) + ":" + ( ( newDate.getMinutes() >=10  )? newDate.getMinutes() : ( "0" +  newDate.getMinutes() )  ) ;
			//console.log(formatTime);
			return formatTime;
		},
		formatData2:function(time){
			var _timestring = time;
			var newDate = new Date();
			newDate.setTime(_timestring * 1000);
			var formatTime = newDate.getFullYear() + "年" + ( ( (newDate.getMonth() + 1) >= 10) ? newDate.getMonth() + 1 : "0" + (newDate.getMonth() + 1)) + "月" + ( ( newDate.getDate() >= 10) ? newDate.getDate() : ("0" + newDate.getDate()) ) + "日 " + (  ( newDate.getHours() >=10  )? newDate.getHours() : ( "0" +  newDate.getHours() )  ) + ":" + ( ( newDate.getMinutes() >=10  )? newDate.getMinutes() : ( "0" +  newDate.getMinutes() )  ) ;
			return formatTime;
		},
		//原有内容
		showCurrentTime:function(){
			var newDate = new Date(); 
			var Week = ['日','一','二','三','四','五','六'];
			var formatTime = newDate.getFullYear() + "年"
			+ ( ( (newDate.getMonth() + 1) >= 10) ? newDate.getMonth() + 1 : "0" + (newDate.getMonth() + 1)) + "月" +
			( ( (newDate.getDate() + 1) >= 10) ? newDate.getDate() : ("0" + newDate.getDate()) ) + "日 " + 
			(  ( newDate.getHours() >=10  )? newDate.getHours() : ( "0" +  newDate.getHours() )  ) + ":" + 
			( ( newDate.getMinutes() >=10  )? newDate.getMinutes() : ( "0" +  newDate.getMinutes() )  ) + 
			":" + ( ( newDate.getSeconds() >=10  )? newDate.getSeconds() : ( "0" +  newDate.getSeconds() ) ) + " " + " 星期" + Week[newDate.getDay()];

			return formatTime;
		},
		
		//当前时间+1天
		nowFormatDate : function() {
			var date = new Date();
			var seperator1 = "-";
			var seperator2 = ":";
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
            var hours = date.getHours();
            var minutes = date.getMinutes();
            var seconds = date.getSeconds();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
            if (hours >= 1 && hours <= 9) {
                hours = "0" + hours;
            }
            if (minutes >= 0 && minutes <= 9) {
                minutes = "0" + minutes;
            }
            if (seconds >= 0 && seconds <= 9) {
                seconds = "0" + seconds;
            }
			var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
					+ " " + hours + seperator2 + minutes
					+ seperator2 + seconds;
			return currentdate;
		},
		//在当前时间的基础上向前相应的时间跨度
		changeDateByParam : function(day,hour,minu,second){
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hours = date.getHours();
            var minutes = date.getMinutes();
            var seconds = date.getSeconds();
            if(day != null && day != "" && day != undefined){
                strDate = strDate -day;
			}
            if(hour != null && hour != "" && hour != undefined){
                hours = hours -hour;
            }
            if(minu != null && minu != "" && minu != undefined){
                minutes = minutes -minu;
            }
            if(second != null && second != "" && second != undefined){
                seconds = seconds -second;
            }

            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            if (hours >= 1 && hours <= 9) {
                hours = "0" + hours;
            }
            if (minutes >= 0 && minutes <= 9) {
                minutes = "0" + minutes;
            }
            if (seconds >= 0 && seconds <= 9) {
                seconds = "0" + seconds;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + hours + seperator2 + minutes
                + seperator2 + seconds;
            return currentdate;
		}
	},
	
	
	
	/*格式化金额千分位*/
	formatCurrency:function(num){  
		if(null != num){
			num = num.toString().replace(/\$|\,/g,'');  
		    if(isNaN(num))  
		        num = "0";  
		    sign = (num == (num = Math.abs(num)));  
		    num = Math.floor(num*100+0.50000000001);  
		    cents = num%100;  
		    num = Math.floor(num/100).toString();  
		    if(cents<10)  
		    cents = "0" + cents;  
		    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)  
		    num = num.substring(0,num.length-(4*i+3))+','+  
		    num.substring(num.length-(4*i+3));  
		    return (((sign)?'':'-') + num + '.' + cents);  
		} 
	},
	
	//小数点后保留两位
	formatAmount : function(num){
		num += '';  
        num = num.replace(/[^0-9|\.]/g, '');   
        if(/^0+/) 
            num = num.replace(/^0+/, '');  
        if(!/\./.test(num))  
            num += '.00';  
        if(/^\./.test(num))  
            num = '0' + num;  
        num += '00';         
        num = num.match(/\d+\.\d{2}/)[0];  
		return num;	
	},
	
	//去除小数点千分位
	removeFormatCurrency:function (strNum){
		if(null != strNum && "" != strNum){
			while(strNum.indexOf(",") >= 0){
				strNum = strNum.replace(",","");
			}
			/* while(strNum.indexOf(".") >= 0){
				strNum = strNum.substring(0,strNum.length - 3);
			} */
			return strNum;
		}
	},	
		//时间格式转时间戳（秒）
		DateToTimestamp : {
			dateFormat : function (dateTime){
				var timestamp = Date.parse(new Date(dateTime));
				return timestamp / 1000;
			}
		},

	 //获取url请求参数，返回键值对的对象
	 getUrlParams:function(){
	 	var requestParams = {};
	 	if(location.search.indexOf("?") != -1){
	 		var str = location.search.substring(1); 
			strs = str.split("&"); 
			for(var i = 0; i < strs.length; i ++) { 
				requestParams[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
			} 
	 	}
	 	return requestParams;
	 },

	 //对于null、undefined返回空串，其它情况返回原值
	 handleNullStr:function(value){
		if(value){
			return value;
		}
		return "";
	},	

	//判断变量是否定义
	isDefine:function(str){
		var js = "typeof " + str + " != 'undefined'" + " && " + str;
		if(eval(js)){
			return true;
		}
		return false;
	},
};

setInterval(function() {
	var now = util.data.showCurrentTime();
	$('#nowTime').text(now);
}, 1000);
$(window).load(function () {
	
})